package com.lyf.scm.plan.domain.remote.bigdata.facade;

import com.alibaba.fastjson.JSON;
import com.lyf.scm.common.enums.ResponseMsg;
import com.lyf.scm.plan.domain.remote.bigdata.BlOlapRemote;
import com.lyf.scm.plan.domain.remote.bigdata.dto.*;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @author 李兵兵
 * @date 2020/09/25
 */
@Service
@Slf4j
public class BlOlapFacade {
    @Resource
    private BlOlapRemote blOlapRemote;

    public List<WarehouseReceiveQtyDTO> getStockInAndOut(StockInAndOutDTO stockInAndOutDTO){
        log.info("查询实际到货量入参:stockInAndOutDTO:{}", JSON.toJSONString(stockInAndOutDTO));
        Response<List<WarehouseReceiveQtyDTO>> response = blOlapRemote.getStockInAndOut(stockInAndOutDTO);
        if(!ResponseMsg.SUCCESS.getCode().equals(response.getCode())){
            throw new RomeException(ResponseMsg.EXCEPTION_2006.getCode(),ResponseMsg.EXCEPTION_2006.getMsg());
        }
        return response.getData();
    }

    public List<SkuSaleQtyDTO> getBoxSalesDayAvg(DayAvgQueryDTO dayAvgQueryDTO){
        log.info("查询实际销量入参：dayAvgQueryDTO：{}", JSON.toJSONString(dayAvgQueryDTO));
        Response<List<SkuSaleQtyDTO>> response = blOlapRemote.getBoxSalesDayAvg(dayAvgQueryDTO);
        if(!ResponseMsg.SUCCESS.getCode().equals(response.getCode())){
            throw new RomeException(ResponseMsg.EXCEPTION_2006.getCode(),ResponseMsg.EXCEPTION_2006.getMsg());
        }
        return response.getData();
    }

    public List<ProductSaleDTO> getProductBoxSalesRank(BoxRankQueryDTO boxRankQueryDTO){
        log.info("查询商品的CPI排名入参:boxRankQueryDTO:{}", JSON.toJSONString(boxRankQueryDTO));
        Response<List<ProductSaleDTO>> response = blOlapRemote.getProductBoxSalesRank(boxRankQueryDTO);
        if(!ResponseMsg.SUCCESS.getCode().equals(response.getCode())){
            throw new RomeException(ResponseMsg.EXCEPTION_2006.getCode(),ResponseMsg.EXCEPTION_2006.getMsg());
        }
        return response.getData();
    }

    public LayeredSkuCodePageDTO getProductList(ProductListQueryDTO productListQueryDTO){
        log.info("根据分层查询商品入参:productListQueryDTO:{}", JSON.toJSONString(productListQueryDTO));
        Response<LayeredSkuCodePageDTO> response = blOlapRemote.getProductList(productListQueryDTO);
        if(!ResponseMsg.SUCCESS.getCode().equals(response.getCode())){
            throw new RomeException(ResponseMsg.EXCEPTION_2006.getCode(),ResponseMsg.EXCEPTION_2006.getMsg());
        }
        return response.getData();
    }

    /**
     * 多维度查询接口
     * @author wuyuanhang
     * @date 2020/11/05
     * @param olapQueryMetadataDTO 产品列表查询dto
     * @return OlapQueryResultDTO
     */
    public OlapQueryResultDTO queryMultiDimensional(OlapQueryMetadataDTO olapQueryMetadataDTO){
        log.info("多维度查询接口入参>>>olapQueryMetadataDTO:{}", JSON.toJSONString(olapQueryMetadataDTO));
        Response<OlapQueryResultDTO> response = blOlapRemote.queryMultiDimensional(olapQueryMetadataDTO);
        log.info("多维度查询接口返回结果>>>response:{}", JSON.toJSONString(response));
        if(!ResponseMsg.SUCCESS.getCode().equals(response.getCode())){
            throw new RomeException(ResponseMsg.EXCEPTION_2006.getCode(),ResponseMsg.EXCEPTION_2006.getMsg());
        }
        return response.getData();
    }
}
